/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.19
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   其它指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "otherinstruction2view.h"
#include "ui_otherinstruction2view.h"
#include "otherinstructionview.h"
#include "../../programView/programview.h"

OtherInstruction2View::OtherInstruction2View(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::OtherInstruction2View)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
}

OtherInstruction2View::~OtherInstruction2View()
{
    delete ui;
}

void OtherInstruction2View::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void OtherInstruction2View::updateView()
{
    ui->jMaxRate_radioButton->setChecked(false);
    ui->lMaxRate_radioButton->setChecked(false);
    if(EM_OTHER_INSTRUCTION_J_MAX_SPEED == otherInstructionView->selectInstructionType)
    {
        ui->jMaxRate_radioButton->setChecked(true);
        ui->jMaxRate_comboBox->setCurrentIndex(otherInstructionView->jIndex - 1);
        ui->jMaxRate_lineEdit->setText(otherInstructionView->jMaxSpeedValue);

        ui->lMaxRate_radioButton->setChecked(false);
    }
    else if(EM_OTHER_INSTRUCTION_L_MAX_SPEED == otherInstructionView->selectInstructionType)
    {
        ui->lMaxRate_radioButton->setChecked(true);
        ui->lMaxRate_lineEdit->setText(otherInstructionView->lMaxSpeedValue);

        ui->jMaxRate_radioButton->setChecked(false);
    }

    ui->note_lineEdit->setText(otherInstructionView->note);
}

void OtherInstruction2View::getInput()
{
    otherInstructionView->jIndex = ui->jMaxRate_comboBox->currentIndex() + 1;
    otherInstructionView->jMaxSpeedValue = ui->jMaxRate_lineEdit->text();
    otherInstructionView->lMaxSpeedValue = ui->lMaxRate_lineEdit->text();
    otherInstructionView->note = ui->note_lineEdit->text();
}

void OtherInstruction2View::changeLanguage()
{
    ui->retranslateUi(this);
}

void OtherInstruction2View::on_jMaxRate_radioButton_clicked()
{
    emit selectJMaxSpeedInstruction();
}

void OtherInstruction2View::on_lMaxRate_radioButton_clicked()
{
    emit selectLMaxSpeedInstruction();
}

void OtherInstruction2View::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void OtherInstruction2View::on_save_Btn_clicked()
{
    otherInstructionView->getInput();

    emit finishEditInstruction();
    emit saveInstruction(otherInstructionView->instruction);
}

void OtherInstruction2View::on_forward_Btn_clicked()
{
    this->close();
    otherInstructionView->show();
}
